package com.zggk.iroad.greendao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.zggk.iroad.db.BhLxInfo;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "t_bhlx".
*/
public class BhLxInfoDao extends AbstractDao<BhLxInfo, Long> {

    public static final String TABLENAME = "t_bhlx";

    /**
     * Properties of entity BhLxInfo.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "id");
        public final static Property BHLX = new Property(1, String.class, "BHLX", false, "BHLX");
        public final static Property BHLXID = new Property(2, String.class, "BHLXID", false, "BHLXID");
        public final static Property JLDW = new Property(3, String.class, "JLDW", false, "JLDW");
        public final static Property SFJL = new Property(4, String.class, "SFJL", false, "SFJL");
        public final static Property ParentId = new Property(5, Long.class, "parentId", false, "PARENT_ID");
    }

    private Query<BhLxInfo> bhInfo_BHLXQuery;

    public BhLxInfoDao(DaoConfig config) {
        super(config);
    }
    
    public BhLxInfoDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"t_bhlx\" (" + //
                "\"id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"BHLX\" TEXT," + // 1: BHLX
                "\"BHLXID\" TEXT," + // 2: BHLXID
                "\"JLDW\" TEXT," + // 3: JLDW
                "\"SFJL\" TEXT," + // 4: SFJL
                "\"PARENT_ID\" INTEGER NOT NULL );"); // 5: parentId
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"t_bhlx\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, BhLxInfo entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String BHLX = entity.getBHLX();
        if (BHLX != null) {
            stmt.bindString(2, BHLX);
        }
 
        String BHLXID = entity.getBHLXID();
        if (BHLXID != null) {
            stmt.bindString(3, BHLXID);
        }
 
        String JLDW = entity.getJLDW();
        if (JLDW != null) {
            stmt.bindString(4, JLDW);
        }
 
        String SFJL = entity.getSFJL();
        if (SFJL != null) {
            stmt.bindString(5, SFJL);
        }
        stmt.bindLong(6, entity.getParentId());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, BhLxInfo entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String BHLX = entity.getBHLX();
        if (BHLX != null) {
            stmt.bindString(2, BHLX);
        }
 
        String BHLXID = entity.getBHLXID();
        if (BHLXID != null) {
            stmt.bindString(3, BHLXID);
        }
 
        String JLDW = entity.getJLDW();
        if (JLDW != null) {
            stmt.bindString(4, JLDW);
        }
 
        String SFJL = entity.getSFJL();
        if (SFJL != null) {
            stmt.bindString(5, SFJL);
        }
        stmt.bindLong(6, entity.getParentId());
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public BhLxInfo readEntity(Cursor cursor, int offset) {
        BhLxInfo entity = new BhLxInfo( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // BHLX
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // BHLXID
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // JLDW
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // SFJL
            cursor.getLong(offset + 5) // parentId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, BhLxInfo entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setBHLX(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setBHLXID(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setJLDW(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setSFJL(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setParentId(cursor.getLong(offset + 5));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(BhLxInfo entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(BhLxInfo entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(BhLxInfo entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "BHLX" to-many relationship of BhInfo. */
    public List<BhLxInfo> _queryBhInfo_BHLX(Long parentId) {
        synchronized (this) {
            if (bhInfo_BHLXQuery == null) {
                QueryBuilder<BhLxInfo> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.ParentId.eq(null));
                bhInfo_BHLXQuery = queryBuilder.build();
            }
        }
        Query<BhLxInfo> query = bhInfo_BHLXQuery.forCurrentThread();
        query.setParameter(0, parentId);
        return query.list();
    }

}
